		//
//  ProtocolManager.m
//  WisdomZhuHai
//
//  Created by Admin on 14-10-24.
//  Copyright (c) 2014年 wyd. All rights reserved.
//

#import "ProtocolManager.h"
#import "Common.h"
//#import "JSONKit.h"
#import "GTMBase64.h"
#import "NSData+AES256.h"
#import <objc/message.h>
#import "JSON.h"
#import "TransforController.h"



@interface ProtocolManager()

//base64加密
- (NSString*)base64Encrypt:(NSDictionary*)dic;
//AES加密 key为时间戳
- (NSString*)AESEncrypt:(NSString*)s key:(NSString*)key;
//获取时间戳
- (NSString*)getTimeStamp;

@end

@implementation ProtocolManager

ProtocolManager *shareProtocolManager = nil;

+ (ProtocolManager*)shareInstance
{
    if (shareProtocolManager == nil)
    {
        shareProtocolManager = [[ProtocolManager alloc] init];
        shareProtocolManager.server_url = @"http://api.okhaolvxing.com";
        [TransforController testModel:NO];
//        if([TransforController isTestModelOn]){
//            shareProtocolManager.server_url = @"http://127.0.0.1/okhaolvxing";
//        }else{
//            shareProtocolManager.server_url = @"http://api.okhaolvxing.com";
//        }
//        shareProtocolManager.server_url = @"http://127.0.0.1/okhaolvxing";
        //apiurl地址基础前字段
        shareProtocolManager.api_base_url =  [shareProtocolManager.server_url stringByAppendingString:@"/okhaolvxing/index.php"];
//        shareProtocolManager.api_base_url =  [shareProtocolManager.server_url stringByAppendingString:@"/index.php"];
        shareProtocolManager.api_base_img_url = [shareProtocolManager.server_url stringByAppendingString:@"/okhaolvxing/"];
    }
    return shareProtocolManager;
}

#pragma mark - 收藏
- (void)saveCollection:(int)type userName:(NSString*)userName requestId:(NSString*)requestId target:(id)target selector:(SEL)selector
{
    if (self.sid.length == 0) {
        return;
    }
    NSString* encryptedParams = [self base64Encrypt:@{P_TYPE:[NSNumber numberWithInt:type], P_USERNAME:userName, P_REQUESTID:requestId, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:APICOLLECTION operation:R_SAVECOLLECTION params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)cancelCollection:(NSString*)userName requestId:(NSString*)requestId target:(id)target selector:(SEL)selector
{
    if (self.sid.length == 0) {
        return;
    }
    NSString* encryptedParams = [self base64Encrypt:@{P_USERNAME:userName, P_REQUESTID:requestId, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:APICOLLECTION operation:R_CANCELCOLLECTION params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

#pragma mark - 商家
- (void)getStoreType:(id)target selector:(SEL)selector
{
    NSString* urlPath = [self getRequestUrlPath:APIGOWAY operation:R_GETGOWHERE params:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getStoreListWithId:(int)storeId andTarget:(id)target selector:(SEL)selector{
    NSString* encryptedParams = nil;
    NSString* urlPath = nil;
    encryptedParams = [self base64Encrypt:@{P_V2_STOREID:[NSNumber numberWithInt:storeId]}];
    urlPath = [self getRequestUrlPath:P_V2APIGOODS operation:P_V2_GET_GOODS params:@{P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getStoresList:(int)type returnCount:(int)returnCount beginNo:(int)beginNo area:(NSString*)area star:(NSString*)star storeType:(NSString*)storeType target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_TYPE:[NSNumber numberWithInt:type], P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    if (area.length > 0) {
        [params setObject:area forKey:P_AREA];
    }
    if (star.length > 0) {
        [params setObject:star forKey:P_STAR];
    }
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = nil;
    if ([storeType isEqualToString:@"电影院"]) {
        urlPath = [self getRequestUrlPath:APIMOVIECINEMA operation:R_GETMOVIESANDCINEMAS params:nil];
    }
    else if ([storeType isEqualToString:@"选择电影院"]) {
        encryptedParams = [self base64Encrypt:@{P_MOVIEID:[NSNumber numberWithInt:type]}];
        urlPath = [self getRequestUrlPath:APIMOVIECINEMA operation:R_GETCINEMAPLAYTHISMOVIE params:@{P_REQ:encryptedParams}];
    }
    else {
        urlPath = [self getRequestUrlPath:APIGOODS operation:R_GETSTORESLIST params:@{P_REQ:encryptedParams}];
    }
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getGoodsList:(int)price returnCount:(int)returnCount beginNo:(int)beginNo target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = [self base64Encrypt:@{P_PRICE:[NSNumber numberWithInt:price], P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    NSString* urlPath = [self getRequestUrlPath:APIGOODS operation:R_GETGOODSLIST params:@{P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getStoreDetail:(int)store_id sendType:(NSString*)sendType target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = nil;
    NSString* urlPath = nil;
    if ([sendType isEqualToString:@"电影院"]) {
        encryptedParams = [self base64Encrypt:@{P_STROE_ID:[NSNumber numberWithInt:store_id]}];
        urlPath = [self getRequestUrlPath:APIMOVIECINEMA operation:R_GETCINEMATHREEDAYSHOWTIME params:@{P_REQ:encryptedParams}];
    }
    else if ([sendType isEqualToString:@"影院信息"]) {
        encryptedParams = [self base64Encrypt:@{P_CINEMA_ID:[NSNumber numberWithInt:store_id]}];
        urlPath = [self getRequestUrlPath:APIMOVIECINEMA operation:R_GETDETAILCINEMA params:@{P_REQ:encryptedParams}];
    }else if([sendType isEqualToString:@"V2"]){
        encryptedParams = [self base64Encrypt:@{P_V2_STORE_ID:[NSNumber numberWithInt:store_id]}];
        urlPath = [self getRequestUrlPath:P_V2APISTORES operation:P_V2_GET_CONTENT params:@{P_REQ:encryptedParams}];
    }
    else {
        encryptedParams = [self base64Encrypt:@{P_STROE_ID:[NSNumber numberWithInt:store_id]}];
        urlPath = [self getRequestUrlPath:APIGOODS operation:R_GETGOODSLIST params:@{P_REQ:encryptedParams}];
    }
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
//        NSLog(@"==>>ProtocolManager-->>getStoreDetail||dic:%@", dic);
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getSingleGoodDetail:(int)goodId sendType:(NSString*)type target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = nil;
    NSString* urlPath = nil;
    if ([type isEqualToString:@"电影详情"]) {
        encryptedParams = [self base64Encrypt:@{P_MOVIEID:[NSNumber numberWithInt:goodId]}];
        urlPath = [self getRequestUrlPath:APIMOVIECINEMA operation:R_GETDETAILMOVIE params:@{P_REQ:encryptedParams}];
    }
    else if ([type isEqualToString:@"电影票详情"]) {
        encryptedParams = [self base64Encrypt:@{P_GOODID:[NSNumber numberWithInt:goodId]}];
        urlPath = [self getRequestUrlPath:APIMOVIECINEMA operation:R_GETTICKETBUYDETAIL params:@{P_REQ:encryptedParams}];
    }else if([type isEqualToString:@"详情"]){
        encryptedParams = [self base64Encrypt:@{P_ID:[NSNumber numberWithInt:goodId]}];
        urlPath = [self getRequestUrlPath:P_V2APIGOODS operation:P_V2_GET_CONTENT params:@{P_REQ:encryptedParams}];
    }
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

#pragma mark - 用户

- (void)getUserInfo:(NSString *)loginname target:(id)target selector:(SEL)selector{
    NSString* encryptedParams = [self base64Encrypt:@{P_LOGINNAME:loginname, P_TIMESTAMP:[self getTimeStamp], P_SESSIONID:self.sid}];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:P_V2_USERINFO params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getCouponListWithStatus:(int)status andPage:(NSString *)page target:(id)target selector:(SEL)selector{
    NSString* encryptedParams = [self base64Encrypt:@{P_LOGINNAME:[ProtocolManager shareInstance].loginName, P_TIMESTAMP:[self getTimeStamp], P_SESSIONID:self.sid, P_V2_STATUS:[NSNumber numberWithInt:status], P_V2_PAGE:page}];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOUPON operation:P_V2_COUPONLIST params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)login:(NSString*)loginName password:(NSString*)password mobileModel:(NSString*)mobileModel loginCity:(NSString*)loginCity appVersion:(NSString*)appVersion OSversion:(NSString*)OSversion mac:(NSString*)phoneUUID target:(id)target selector:(SEL)selector
{
    NSString *loginTime = password;
    NSString *tempLoginName = loginName;
    NSString *timestamp = [self getTimeStamp];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_LOGINNAME:loginName, P_PASSWORD:[self encodePassword:password timestamp:timestamp], P_MOBILEMODEL:mobileModel, P_APPVERSION:appVersion, P_OSVERSION:OSversion, P_WHICHSOURCE:@"IOS",P_MAC:phoneUUID, P_TIMESTAMP:timestamp}];
//    if (loginCity.length > 0) {
//        [params setObject:loginCity forKey:P_LOGINCITY];
//    }
    [params setObject:@"珠海" forKey:P_LOGINCITY];
//    if (mac.length > 0) {
//        [params setObject:mac forKey:P_MAC];
//    }
    NSString* urlPath = @"";
    if ([tempLoginName  isEqual: @"匿名用户"]){
        urlPath = [self getRequestUrlPath:APIUSER operation:R_ANYLOGIN params:nil];
        [params setObject:loginTime forKey:P_ANONY_OPEN];
        [params setObject:timestamp forKey:P_ANONY_CLOSE];
    } else {
        urlPath = [self getRequestUrlPath:APIUSER operation:R_LOGIN params:nil];
    }
    NSString* encryptedParams = [self base64Encrypt:params];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
//        NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)register:(NSString*)loginName password:(NSString*)password mobileModel:(NSString*)phoneModel loginCity:(NSString*)loginCity mac:(NSString*)mac target:(id)target selector:(SEL)selector
{
    NSString *timestamp = [self getTimeStamp];
//    NSString* encryptedParams = [self base64Encrypt:@{P_LOGINNAME:loginName, P_PASSWORD:[self encodePassword:password timestamp:timestamp], P_TIMESTAMP:timestamp}];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_LOGINNAME:loginName, P_PASSWORD:[self encodePassword:password timestamp:timestamp], P_WHICHSOURCE:@"IOS", P_TIMESTAMP:timestamp}];
    if (loginCity.length > 0) {
        [params setObject:loginCity forKey:P_LOGINCITY];
    }
    if (mac.length > 0) {
        [params setObject:mac forKey:P_MAC];
    }
    NSString* encryptedParams = [self base64Encrypt:params];
    
    NSLog(@"%s || encryptedParam:%@", __FUNCTION__, encryptedParams);
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:R_REGISTER params:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)logout:(id)target selector:(SEL)selector
{
    if (self.sid.length == 0) {
        objc_msgSend(target, selector, nil);
    }
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_SID:self.sid, P_USERID:[NSNumber numberWithInt:self.userId]}];
    NSLog(@"ProtocolManager-->>logout||params:%@",params);
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:R_USERLOGOUT params:nil];
    NSString* encryptedParams = [self base64Encrypt:params];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        NSLog(@"%@", dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)update:(NSString *)username gender:(NSString *)gender birthday:(NSString *)birthday industry:(NSString *)industry email:(NSString *)email address:(NSString *)address target:(id)target selector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_SID:self.sid, P_USERID:[[NSString alloc]initWithFormat:@"%d", self.userId], P_LOGINNAME:self.loginName}];
    [params setObject:username forKey:P_USERNAME];
    [params setObject:gender forKey:@"sex"];
    [params setObject:birthday forKey:P_BIRTHDAY];
    //[params setObject:industry forKey:P_INDUSTRY];
    [params setObject:email forKey:P_EMAIL];
    [params setObject:address forKey:P_ADDRESS];
    NSLog(@"==>>protocolManager-->>update||params:%@",params);
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:R_UPDATEUSERINFO params:nil];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSLog(@"==>>protocolManager-->>update||encryptedParams:%@",encryptedParams);
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"%@", dic);
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)mobileLogin:(NSString*)mobile mobileModel:(NSString*)mobileModel loginCity:(NSString*)loginCity appVersion:(NSString*)appVersion OSversion:(NSString*)OSversion mac:(NSString*)mac target:(id)target selector:(SEL)selector{
    /*NSString *loginTime = password;
    NSString *tempLoginName = loginName;
    if ([tempLoginName  isEqual: @"匿名用户"]) {
        //loginName = [loginName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        loginName = @"&#x533F;&#x540D;&#x7528;&#x6237;";
    }
    */
    NSString *timestamp = [self getTimeStamp];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_MOBILE:mobile, P_MOBILEMODEL:mobileModel, P_APPVERSION:appVersion, P_OSVERSION:OSversion, P_WHICHSOURCE:@"IOS", P_TIMESTAMP:timestamp}];
    if (loginCity.length > 0) {
        [params setObject:loginCity forKey:P_LOGINCITY];
    }
    if (mac.length > 0) {
        [params setObject:mac forKey:P_MAC];
    }
    NSString* urlPath = @"";
    /*
    if ([tempLoginName  isEqual: @"匿名用户"]){
        urlPath = [self getRequestUrlPath:APIUSER operation:R_ANYLOGIN params:nil];
        [params setObject:loginTime forKey:P_ANONY_OPEN];
        [params setObject:timestamp forKey:P_ANONY_CLOSE];
    } else {*/
        urlPath = [self getRequestUrlPath:APIUSER operation:R_MOBILELOGIN params:nil];
    //}
    NSString* encryptedParams = [self base64Encrypt:params];
    
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)mobileBinding:(NSString *)loginName mobile:(NSString *)mobile target:(id)target selector:(SEL)selector{
    if (self.sid.length == 0) {
        return;
    }
    NSString* encryptedParams = [self base64Encrypt:@{P_LOGINNAME:loginName, P_MOBILE:mobile, P_TIMESTAMP:[self getTimeStamp], P_SESSIONID:self.sid}];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:R_MOBILEBIND params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    //NSString *urlPath = [self getRequestUrlPath:APIUSER operation:R_MOBILEBIND params:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

#pragma mark - 订单
- (void)getOrderList:(NSString*)loginName pageIndex:(NSString*)pageIndex andStatus:(int)status target:(id)target selector:(SEL)selector
{
    if (self.sid.length == 0) {
        return;
    }
    NSString* encryptedParams = [self base64Encrypt:@{P_LOGINNAME:loginName, P_PAGE:pageIndex,P_V2_STATUS:[NSNumber numberWithInt:status] , P_TIMESTAMP:[self getTimeStamp], P_SESSIONID:self.sid}];
    NSString* urlPath = [self getRequestUrlPath:APIORDER operation:P_ORDER_LIST params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSDictionary *dic = [tempDic objectForKey:@"result"];
        NSLog(@"%s ||dic:%@", __FUNCTION__, dic);
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

#pragma mark - 首页专题
//首页专题
-(void)getSlidesAndSpecial:(id)target selector:(SEL)selector
{
    NSString* urlPath = [self getRequestUrlPath:V2APIHOMEPAGE operation:R_GETSLIDESANDSPECIAL params:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}

#pragma mark - 资讯
-(void)getMessageList:(int)typeId topicId:(int)topicId returnCount:(int)returnCount beginNo:(int)beginNo target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary: @{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    if(typeId > 0)
    {
        [params setValue:[NSNumber numberWithInt:typeId] forKey:P_TYPEID];
    }
    if(topicId > 0)
    {
        [params setValue:[NSNumber numberWithInt:topicId] forKey:P_TOPICID];
    }
    NSString* encodeParams = [self base64Encrypt:params];
    params = [NSMutableDictionary dictionaryWithDictionary:@{P_REQ:encodeParams}];
//    params = [NSMutableDictionary dictionaryWithDictionary:@{P_REQ:[params JSONString]}];
    NSString* urlPath = [self getRequestUrlPath:APINEWSRELEASE operation:R_GETNEWSRELEASE params:params];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithDictionary:dic];
        [mDic setValue:[NSString stringWithFormat:@"%d",typeId] forKey:P_TYPEID];
        objc_msgSend(target, selector, mDic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

#pragma mark - 攻略
- (void)getClassify:(id)target selector:(SEL)selector
{
    NSString* urlPath = [self getRequestUrlPath:V2_APISTRATEGY operation:R_GETCLASSIFY params:nil];
    NSLog(@"攻略列表接口地址为：%@",urlPath);
    
    [[Common shareInstance]showLoadingViewWithMessage:@"读取中"];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

//- (void)getStrategy:(NSNumber*)Id target:(id)target selector:(SEL)selector
//{
//    NSDictionary* params = nil;
//    if (Id != nil) {
//        params = @{P_ID:Id};
//        NSString* encodeParams = [self base64Encrypt:params];
//        params = @{P_REQ:encodeParams};
////        params = @{P_REQ:[params JSONString]};
//    }
//    NSString* urlPath = [self getRequestUrlPath:APISTRATEGY operation:R_GETSTRATEGY params:params];
//    
//    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [self didRequestSuccess:request];
//        NSDictionary *dic = [self dictionaryFromRequest:request];
//        objc_msgSend(target, selector, dic);
//    } failure:^(ASIHTTPRequest* request){
//        [self didRequestFailure:request];
//        objc_msgSend(target, selector, nil);
//    }];
//}
//http://api.okhaolvxing.com/okhaolvxing/index.php/ApiStrategy/getStrategyb?id=28
- (void)getStrategy:(NSNumber*)Id target:(id)target selector:(SEL)selector
{
    NSDictionary* params = nil;
    if (Id != nil) {
        params = @{P_ID:Id};
//        NSString* encodeParams = [self base64Encrypt:params];
//        params = @{P_REQ:encodeParams};
        //        params = @{P_REQ:[params JSONString]};
    }
    NSString* urlPath = [self getRequestUrlPath:APISTRATEGY operation:R_GETSTRATEGYB params:params];
    
//    [[Common shareInstance]showLoadingViewWithMessage:@"读取中"];
//    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//       [[Common shareInstance]stopLoadingView];
//        [self didRequestSuccess:request];
//        NSDictionary *dic = [self dictionaryFromRequest:request];
//        objc_msgSend(target, selector, dic);
//    } failure:^(ASIHTTPRequest* request){
//        [[Common shareInstance]stopLoadingView];
//        [self didRequestFailure:request];
//        objc_msgSend(target, selector, nil);
//    }];
    [[Common shareInstance]showLoadingViewWithMessage:@"读取中"];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getContent:(int)Id target:(id)target selector:(SEL)selector
{
    NSDictionary* params = @{P_ID:[NSNumber numberWithInt:Id]};
    NSString* encryptedParams = [self base64Encrypt:params];
    params = @{P_REQ:encryptedParams};
    NSString* urlPath = [self getRequestUrlPath:APISTRATEGY operation:R_GETCONTENT params:params];
    NSLog(@"********URL %@",urlPath);
    
    [[Common shareInstance]showLoadingViewWithMessage:@"读取中"];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        NSMutableDictionary *mDic = nil;
        if (dic != nil) {
            mDic = [NSMutableDictionary dictionaryWithDictionary:dic];
            [mDic setObject:[NSNumber numberWithInt:Id] forKey:P_ID];
        }
        objc_msgSend(target, selector, mDic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getNewContent:(int)Id target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = [NSString stringWithFormat:@"%@=%d",P_ID,Id];
    NSMutableString* urlPath = [NSMutableString stringWithFormat:@"%@/%@/%@", self.api_base_url, APISTRATEGY, R_GETSTRATEGYB];
    [urlPath appendFormat:@"?%@", encryptedParams];
    
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil
    success:^(ASIHTTPRequest* request){
            [[Common shareInstance] stopLoadingView];
            [self didRequestSuccess:request];
            NSDictionary *dic = [self dictionaryFromRequest:request];
            objc_msgSend(target, selector, dic, Id);
    }failure:^(ASIHTTPRequest* request){
            [[Common shareInstance] stopLoadingView];
            [self didRequestFailure:request];
            objc_msgSend(target, selector, nil, Id);
    }];
}


#pragma mark - 工具
- (void)getToolsWithCity:(NSString *)city andTarget:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = [self base64Encrypt:@{P_V2_CITY:city}];
    NSMutableString* urlPath = [NSMutableString stringWithFormat:@"%@/%@/%@", self.api_base_url, APITOOL, R_GETTOOLS];
    [urlPath appendFormat:@"/req/%@", encryptedParams];
    
//    [[Common shareInstance]showLoadingViewWithMessage:@"读取中"];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [[Common shareInstance]stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
//        [[Common shareInstance]stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

//获取助手2级页面tool列表
-(void)getToolDetailsListWithId:(NSString *)tId andTarget:(id)target selector:(SEL)selector{
    NSString *encryptedParams = [self base64Encrypt:@{P_V2_TOOLID:tId}];
    NSMutableString* urlPath = [NSMutableString stringWithFormat:@"%@/%@/%@", self.api_base_url, APITOOL, R_GETTOOLITEMS];
    [urlPath appendFormat:@"/req/%@", encryptedParams];

    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance]stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

////v2.0 通过ID获取相应新闻页面URL链接
//-(void)getNewsDetailWithId:(int)tId andTarget:(id)target selector:(SEL)selector{
//    NSString *encryptedParams = [NSString stringWithFormat:@"id=%d",tId];
//    NSMutableString* urlPath = [NSMutableString stringWithFormat:@"%@/%@/%@", self.api_base_url, APINEWRELEASE, R_GETCONTENT];
//    [urlPath appendFormat:@"?%@", encryptedParams];
//    NSLog(@"%@",urlPath);
//    
//    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [self didRequestSuccess:request];
//        NSURL *dic = [self dictionaryFromRequest:request];
//        objc_msgSend(target, selector, dic);
//    } failure:^(ASIHTTPRequest* request){
//        [self didRequestFailure:request];
//        objc_msgSend(target, selector, nil);
//    }];
//}


#pragma mark - 支付
- (void)allowance:(NSString*)allowance target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = [self base64Encrypt:@{P_SN:allowance, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:APICOUPON operation:P_SEARCHCOUPON params:@{P_REQ:encryptedParams}];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}

- (void)mobileValidation:(NSString*)mobile target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = [self base64Encrypt:@{P_MOBILE:mobile, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:APIORDER operation:R_MOBILEVALIDATION params:@{P_REQ:encryptedParams}];
    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)submitOrder:(int)productId mobile:(NSString*)mobile couponCode:(NSString*)couponCode num:(int)num orderPrice:(CGFloat)orderPrice orderSN:(NSString*)orderSN note:(NSString*)note target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{ P_PRODUCTID:[NSNumber numberWithInt:productId], P_NUM:[NSNumber numberWithInt:num], P_ORDERPRICE:[NSNumber numberWithFloat:orderPrice], P_TIMESTAMP:[self getTimeStamp]}];
    if (note.length > 0) {
        [params setObject:note forKey:P_NOTE];
    }
    if (mobile.length > 0) {
        [params setObject:mobile forKey:P_MOBILE];
    }
    if (orderSN.length > 0) {
        [params setObject:orderSN forKey:P_ORDERSN];
    }
    if (self.loginName.length > 0) {
        [params setObject:self.loginName forKey:P_LOGINNAME];
        [params setObject:self.sid forKey:P_SESSIONID];
    }
    if (couponCode.length > 0) {
        [params setObject:couponCode forKey:P_COUPONCODE];
    }
    NSString* encryptedParams = [self base64Encrypt:params];
    
    NSDictionary* urlParams = @{P_REQ:encryptedParams};
    if (mobile.length == 0 && self.sid.length > 0) {
        urlParams = @{P_REQ:encryptedParams, P_SID:self.sid};
    }
    NSString* urlPath = [self getRequestUrlPath:APIORDER operation:R_SUBMITORDER params:urlParams];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)confirmOrderPay:(NSString*)orderSN payWay:(NSString*)payWay isUseBalance:(int)isUseBalance coupon:(NSString*)coupon target:(id)target selector:(SEL)selector
{
    if (self.sid.length == 0 || orderSN.length == 0) {
        return;
    }
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_ORDERSN:orderSN, P_ISUSEBALANCE:[NSNumber numberWithInt:isUseBalance], P_PAYWAY:payWay, P_TIMESTAMP:[self getTimeStamp]}];
    if (coupon.length > 0) {
        [params setObject:coupon forKey:P_COUPON];
    }
    if (self.loginName.length > 0) {
        [params setObject:self.loginName forKey:P_LOGINNAME];
        [params setObject:self.sid forKey:P_SESSIONID];
    }
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:APIORDER operation:R_CONFIRMORDERPAY params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)completeOrder:(NSString*)status paystatus:(NSString*)paystatus orderSN:(NSString*)orderSN note:(NSString*)note target:(id)target selector:(SEL)selector
{
    if (self.sid.length == 0 || orderSN.length == 0) {
        return;
    }
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_ORDERSN:orderSN, P_TIMESTAMP:[self getTimeStamp]}];
    if (status.length > 0) {
        [params setObject:status forKey:P_STATUS];
    }
    if (paystatus.length > 0) {
        [params setObject:paystatus forKey:P_PAYSTATUS];
    }
    if (note.length > 0) {
        [params setObject:note forKey:P_NOTE];
    }
    
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:APIORDER operation:R_COMPLETEORDER params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)orderRefund:(NSString*)orderSN confirm:(BOOL)confirm target:(id)target selector:(SEL)selector
{
    NSDictionary *params = @{P_LOGINNAME:self.loginName, P_SESSIONID:self.sid, P_TIMESTAMP:[self getTimeStamp], P_ORDERSN:orderSN};
    NSString *encodeParams = [self base64Encrypt:params];
    NSString *urlPath = nil;
    if (confirm == NO) {
        urlPath = [self getRequestUrlPath:APIORDER operation:R_ORDERREFUND params:@{P_SID:self.sid, P_REQ:encodeParams}];
    } else {
        urlPath = [self getRequestUrlPath:APIORDER operation:R_ORDERREFUNDCONFIRM params:@{P_SID:self.sid, P_REQ:encodeParams}];
    }
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getOrderDetail:(NSString*)orderSN target:(id)target selector:(SEL)selector
{
    NSDictionary *params = @{P_LOGINNAME:self.loginName, P_SESSIONID:self.sid, P_TIMESTAMP:[self getTimeStamp], P_ORDERSN:orderSN};
    NSString *encodeParams = [self base64Encrypt:params];
    NSString *urlPath = [self getRequestUrlPath:APIORDER operation:R_ORDERDETAIL params:@{P_SID:self.sid, P_REQ:encodeParams}];;
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}

- (void)cancelOrder:(NSString*)orderSN target:(id)target selector:(SEL)selector
{
    NSDictionary *params = @{P_LOGINNAME:self.loginName, P_SESSIONID:self.sid, P_TIMESTAMP:[self getTimeStamp], P_ORDERSN:orderSN};
    NSString *encodeParams = [self base64Encrypt:params];
    NSString *urlPath = [self getRequestUrlPath:APIORDER operation:R_ORDERCANCEL params:@{P_SID:self.sid, P_REQ:encodeParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
    
}

//设置相关
-(void)getUpdateInfo:(id)target selector:(SEL)selector
{
    NSDictionary *params = @{P_PLATFORM:@"ios"};
    NSString* encodeParams = [self base64Encrypt:params];
    params = @{P_REQ:encodeParams};
    NSString* urlPath = [self getRequestUrlPath:APIUPDATE operation:R_UPDATE params:params];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}
-(void)getAppEvaluateUrl:(id)target selector:(SEL)selector
{
    NSString* urlPath = [self getRequestUrlPath:APIAPPEVALUATE operation:R_GETSTOREURL params:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}
//提交反馈协议
-(void)feedBack:(NSString *)loginName msg:(NSString *)mgs OSversion:(NSString*)OSversion target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary: @{P_MSG:mgs , P_PLATFORM:OSversion}];
    if(loginName.length > 0)
    {
        [params setValue:loginName forKey:P_LOGINNAME];
    }
    NSString* encodeParams = [self base64Encrypt:params];
    //       params = @{P_REQ:encodeParams};
    params = [NSMutableDictionary dictionaryWithDictionary:@{P_REQ:encodeParams}];
    NSString* urlPath = [self getRequestUrlPath:APIFEEDBACK operation:R_SENDMSG params:params];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithDictionary:dic];
        objc_msgSend(target, selector, mDic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}

#pragma mark - 2.0

//首页新闻列表
- (void)getHomePageNewsList:(int)returnCount beginNo:(int)beginNo target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:V2APINEWS operation:P_V3_GETHOMENEWS params:@{P_REQ:encryptedParams}];//获取API
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}

//新闻列表（内含专题cell）/Bable
/*
 普通的参数注释
 category_id 专题种类（目前不需要，默认0）
 andCount:(int)returnCount 拿到到第n条专题
 beginNo:(int)beginNo 从第n条专题开始拿
 */
- (void)getNewsListWithCategoryId:(int)category_id andCount:(int)returnCount beginNo:(int)beginNo target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params;
    if(category_id == 0){
    params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    }else{
        params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_CATEGORYID:[NSNumber numberWithInt:category_id], P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    }
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:V2APINEWS operation:R_GETNEWS params:@{P_REQ:encryptedParams}];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

/*
//专题列表-Bable

// 普通的参数注释
// category_id 专题种类（目前不需要，默认0）
// andCount:(int)returnCount 拿到到第n条专题
// beginNo:(int)beginNo 从第n条专题开始拿

- (void)getTopSpecialListWithCategoryId:(int)category_id andCount:(int)returnCount beginNo:(int)beginNo target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params;
//    if(category_id == 0){
//        params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
//    }else{
//        params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_CATEGORYID:[NSNumber numberWithInt:category_id], P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
//    }

    //编辑请求字段
    params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    //加密请求字段
    NSString* encryptedParams = [self base64Encrypt:params];
//    NSString* urlPath = [self getRequestUrlPath:V2APINEWS operation:R_GETNEWS params:@{P_REQ:encryptedParams}];
    NSString* urlPath = P_TOPIC_API_URLPATH;
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}
*/

//食住行娱乐购列表
- (void)getFLWTEBList:(int)returnCount beginNo:(int)beginNo typeId:(int)typeId API:(NSString*)API REQ:(NSString*)REQ andDistance:(NSString *)distance tag:(NSString *)tag areaName:(NSString *)areaName target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo], P_TYPEID:[NSNumber numberWithInt:typeId]}];
    if(tag != nil){
        [params setObject:tag forKey:P_V2_TAG];
    }
    if(areaName != nil){
        [params setObject:areaName forKey:P_V2_AREANAME];
    }
    if(_latitude != 0 || _longitude != 0) {
        NSString *gps = [NSString stringWithFormat:@"%f,%f",_longitude, _latitude];
        [params setObject:gps forKey:P_V2_GPS];
        if (distance != nil) {
            [params setObject:distance forKey:P_V2_RADIUS];
        }
    }
    NSLog(@"%s || params:%@", __FUNCTION__, params);
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:API operation:REQ params:@{P_REQ:encryptedParams}];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];

}

- (void)getFLWTEBFliterExtraTypeWithTypeId:(int)typeId andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_TYPEID:[NSNumber numberWithInt:typeId]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APISTORES operation:P_V2_GET_EXTRATYPE params:@{P_REQ:encryptedParams}];
//    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getFLWTEBFliterDistrictWithTarget:(id)target andSelector:(SEL)selector{
    NSString* urlPath = [self getRequestUrlPath:P_V2APISTORES operation:P_V2_GET_AREA params:nil];
//    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getOkListWithStatus:(int)status andPage:(int)page target:(id)target selector:(SEL)selector{
    NSString* encryptedParams = [self base64Encrypt:@{P_LOGINNAME:[ProtocolManager shareInstance].loginName, P_TIMESTAMP:[self getTimeStamp], P_SESSIONID:self.sid, P_V2_STATUS:[NSNumber numberWithInt:status], P_V2_PAGE:[NSNumber numberWithInt:page]}];
    NSString* urlPath = [self getRequestUrlPath:APIORDER operation:P_V2_GET_SN params:@{P_SID:self.sid, P_REQ:encryptedParams}];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)mobileValidationWithMobile:(NSString*)mobile target:(id)target selector:(SEL)selector
{
    NSString* encryptedParams = [self base64Encrypt:@{P_MOBILE:mobile, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:P_V2_GET_MOBILE_CODE  params:@{P_REQ:encryptedParams}];
    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getVerifyCodeWithMobile:(NSString *)mobile target:(id)target selector:(SEL)selector{
    NSString* encryptedParams = [self base64Encrypt:@{P_MOBILE:mobile, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:P_V2_GET_MOBILE_VERIFY_CODE  params:@{P_REQ:encryptedParams}];
    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)likeWithTypeName:(NSString *)typeName andTargetId:(int)targetId andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_TYPE:typeName, P_V2_ID:[NSNumber numberWithInt:targetId]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APIGOOD operation:P_V2_ADD_LIKE params:@{P_REQ:encryptedParams}];
    //    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)addToCollectionWithType:(NSString *)typeName andUsername:(NSString *)loginName andTargetId:(int)target_id andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_USERNAME:loginName, P_V2_TYPE:typeName, P_V2_RELATED_ID:[NSNumber numberWithInt:target_id], P_SESSIONID:self.sid, P_TIMESTAMP:[self getTimeStampString]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOLLECTIONS operation:P_V2_ADD_COLLECTION params:@{P_REQ:encryptedParams}];
//    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}
- (void)getCollectionsWithLoginName:(NSString *)loginName andCount:(int)returnCount beginNo:(int)beginNo andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_USERNAME:loginName, P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOLLECTIONS operation:P_V2_GET_COLLECTION params:@{P_REQ:encryptedParams}];
    //    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
//    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
//        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getCollectionWithType:(NSString *)type andLoginname:(NSString *)loginname andCount:(int)count andBeginNo:(int)beginNo andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_USERNAME:loginname, P_RETURNCOUNT:[NSNumber numberWithInt:count], P_BEGINNO:[NSNumber numberWithInt:beginNo], P_V2_TYPE:type}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOLLECTIONS operation:P_V2_GET_COLLECTION params:@{P_REQ:encryptedParams}];
    //    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)deleteFromCollectionWithType:(NSString *)typeName andUsername:(NSString *)loginName andTargetId:(int)target_id andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_USERNAME:loginName, P_V2_TYPE:typeName, P_V2_RELATED_ID:[NSNumber numberWithInt:target_id], P_SESSIONID:self.sid, P_TIMESTAMP:[self getTimeStampString]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOLLECTIONS operation:P_V2_DELETE_COLLECTION params:@{P_REQ:encryptedParams}];
    //    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getSiftStoreList:(NSArray*)tagsList typesList:(NSArray*)typesList areasList:(NSArray*)areasList distance:(NSString*)distance returnCount:(int)returnCount beginNo:(int)beginNo target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo], P_TIMESTAMP:[self getTimeStamp]}];
    if([tagsList count] > 0){
        [params setObject:tagsList forKey:P_V2_TYPES];
    }
    if([typesList count] > 0){
        [params setObject:typesList forKey:P_TAGS];
    }
    if ([areasList count] > 0) {
        [params setObject:areasList forKey:@"areaName"];
    }
    if(_latitude != 0 || _longitude != 0) {
        NSString *gps = [NSString stringWithFormat:@"%f,%f",_longitude, _latitude];
        [params setObject:gps forKey:P_V2_GPS];
        if (distance != nil) {
            [params setObject:distance forKey:P_V2_RADIUS];
        }
    }
    NSString *jsonString = [params JSONFragment];
    NSString* urlPath = [self getRequestUrlPath:V2APICUSTOM operation:R_GETCUSTOM params:nil];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:jsonString} success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getCommentListWithTargetId:(int)target_id andType:(NSString *)type andReturnCount:(int)count andBeginNo:(int)beginNo andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_COMMENT_TYPE:type, P_V2_COMMENT_ID:[NSNumber numberWithInt:target_id], P_RETURNCOUNT:[NSNumber numberWithInt:count], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOMMENTS operation:P_V2_GET_COMMENT params:@{P_REQ:encryptedParams}];
    //    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)sendCommentWithTargetId:(int)target_id andType:(NSString *)type andContent:(NSString *)content andUserId:(int)user_id andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_COMMENT_TYPE:type, P_V2_COMMENT_CONTENT:content, P_V2_COMMENT_REL_ID:[NSNumber numberWithInt:target_id], P_V2_COMMENT_USER_ID:[NSNumber numberWithInt:user_id]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:P_V2APICOMMENTS operation:P_V2_ADD_COMMENT params:nil];
    //    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
//    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getGlobalSearch:(NSString*)keyword target:(id)target returnCount:(int)returnCount beginNo:(int)beginNo selector:(SEL)selector {
    NSString* encryptedParams = [self base64Encrypt:@{P_V2_KEYWORD:keyword,P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo], P_TIMESTAMP:[self getTimeStamp]}];
    NSString* urlPath = [self getRequestUrlPath:V2APIRETRIEVE operation:R_GLOBALRETRIEVE params:nil];
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)sendChangePasswordWithOld:(NSString *)password andNewPassword:(NSString *)newPassword andLoginName:(NSString *)loginname andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_PASSWORD:password, P_V2_PASSWORD_NEW:newPassword, P_LOGINNAME:loginname, P_SESSIONID:self.sid}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:P_V2_SET_PASSWORD_WITH_OLD params:nil];
        NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    //    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] postParams:@{P_REQ:encryptedParams} success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)sendChangePasswordWithNew:(NSString *)password andMobile:(NSString *)mobile andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_PASSWORD_NEW:password, P_MOBILE:mobile}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:P_V2_SET_PASSWORD_WITH_NEW params:@{P_REQ:encryptedParams}];
    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)sendVerifyMailWithMail:(NSString *)mail andTarget:(id)target andSelector:(SEL)selector{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_MAIL:mail}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:APIUSER operation:P_V2_GET_EMAIL_VERIFY params:@{P_REQ:encryptedParams}];
    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

- (void)getCouponListForPay:(NSString*)orderSn andTarget:(id)target andSelector:(SEL)selector {
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithDictionary:@{P_ORDERSN:orderSn, P_LOGINNAME:_loginName, P_SESSIONID:self.sid, P_TIMESTAMP:[self getTimeStamp]}];
    NSString* encryptedParams = [self base64Encrypt:params];
    NSString* urlPath = [self getRequestUrlPath:APICOUPON operation:R_V2_SEARCHCOUPONLIST params:@{P_SID:_sid, P_REQ:encryptedParams}];
    NSLog(@"%s || encryptedParams:%@", __FUNCTION__, encryptedParams);
    //    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        //NSLog(@"==>>ProtocolManager-->>login||(NSString)dic:%@",dic);
        if (selector == nil) {
            return;
        }
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

#pragma mark - Private
- (NSString*)base64Encrypt:(NSDictionary*)dic
{
    if (dic == nil) {
        return nil;
    }
    NSString *params = [dic JSONRepresentation];
    //NSString *encryptedParams = [GTMBase64 stringByEncodingBytes:[params UTF8String] length:params.length];
    
    NSData* xmlData = [params dataUsingEncoding:NSUTF8StringEncoding];
    NSString *encryptedParams = [GTMBase64 stringByEncodingData:xmlData];
    return encryptedParams;
}

- (NSString*)AESEncrypt:(NSString*)s key:(NSString*)key;
{
    NSData *encodeData = [[s dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptWithKey:key];
    NSString* result = [[NSString alloc] initWithData:encodeData encoding:NSASCIIStringEncoding];
    return result;
}

- (NSString*)encodePassword:(NSString*)password timestamp:(NSString*)timestamp
{
    NSData *passWordData = [password dataUsingEncoding:NSUTF8StringEncoding];
    //NSData *aesEncoded = [passWordData AES256EncryptWithKey:timestamp];


//    NSArray* chars = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"a",@"b",@"c",@"d",@"e",@"f"];
//    NSMutableString *result = [NSMutableString string];
//    unsigned char *bytes = new unsigned char(aesEncoded.length);
//    [aesEncoded getBytes:bytes];
//    for (int i=0; i < aesEncoded.length; i++) {
//        unsigned char byte = bytes[i];
//        [result appendString:chars[(byte>>4)]];
//        [result appendString:chars[(byte&0xF)]];
//    }
//    NSData *base64 = [GTMBase64 encodeData:[result dataUsingEncoding:NSUTF8StringEncoding]];
//      NSString *result = [aesEncoded base64Encoding];
//    NSData *te = [GTMBase64 encodeData:aesEncoded];
//    NSString *last = [[NSString alloc] initWithData:te  encoding:NSUTF8StringEncoding];
    NSString *result = [passWordData base64Encoding];
    return result;
}

- (NSString*)getTimeStamp
{
    NSDate *date = [NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"yyyy-MM-dd HH-mm-ss"];
    return [dateformatter stringFromDate:date];
}

- (NSString *)getTimeStampString{
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"yyyy-MM-dd HH-mm-ss"];
    NSDate *datenow = [NSDate date];
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
    NSLog(@"%s || timeSp:%@",__FUNCTION__, timeSp);
//    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1296035591];
//    NSLog(@"%s || 1296035591  = %@",__FUNCTION__, confromTimesp);
//    NSString *confromTimespStr = [dateformatter stringFromDate:confromTimesp];
//    NSLog(@"%s || confromTimespStr =  %@",__FUNCTION__, confromTimespStr);
    return timeSp;
}

//apiurl地址获取器 /Bable
/*
 category: api类型（名称）
 operation: 所执行的操作名
 params: 其他长参数
*/
- (NSString*)getRequestUrlPath:(NSString*)category operation:(NSString*)operation params:(NSDictionary*)params
{
    NSMutableString* urlPath = [NSMutableString stringWithFormat:@"%@/%@/%@", self.api_base_url, category, operation];
    if (params != nil && [params allKeys].count > 0) {
        NSMutableArray* sParams = [NSMutableArray array];
        for (NSString* key in [params allKeys]) {
            NSString* s = [NSString stringWithFormat:@"%@=%@", key, params[key]];
            [sParams addObject:s];
        }
        [urlPath appendFormat:@"?%@", [sParams componentsJoinedByString:@"&"]];
    }
    return urlPath;
}

- (NSDictionary*)dictionaryFromRequest:(ASIHTTPRequest*)request
{
    NSString *jsonString = request.responseString;
    id obj = [jsonString JSONValue];
    if ([obj isKindOfClass:[NSDictionary class]]) {
        return (NSDictionary*)obj;
    }
    else {
        NSData *data = [GTMBase64 decodeString:jsonString];
        jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        obj = [jsonString JSONValue];
        if ([obj isKindOfClass:[NSDictionary class]]) {
            return (NSDictionary*)obj;
        }
        return nil;
    }
}

- (void)didRequestSuccess:(ASIHTTPRequest*)request
{
    NSDictionary* dic = [self dictionaryFromRequest:request];
    if (dic == nil) {
        NSLog(@"返回数据为空！");
        [[Common shareInstance] showAlertViewWithTitle:@"获取数据失败！" text:nil dismissTime:1.0f];
    }
    else {
        NSString* respCode = [Common valueForKey:P_RESPCODE dic:dic];
        NSString* respDesc = [Common valueForKey:P_RESPDESC dic:dic];
        if (respDesc == nil || respCode == nil) {
            return;
        }
        if (![respCode isEqualToString:@"000"]) {
            NSString *errorMsg = [NSString stringWithFormat:@"%@",respDesc];
            NSLog(@"%s || %@ %@", __FUNCTION__, respCode, errorMsg);
            [[Common shareInstance] showAlertViewWithTitle:errorMsg text:nil dismissTime:2.0f];
        }
    }
}

- (void)didRequestFailure:(ASIHTTPRequest*)request
{
    
}

//- (void) anonyLoginPost:(NSString*)url





//专题页面（内含专题cell）Bable-

- (void)getTopSpecailDetailsWithTopicId:(int)topicId target:(id)target selector:(SEL)selector
{
    NSMutableDictionary* params;

//        params = [NSMutableDictionary dictionaryWithDictionary:@{P_RETURNCOUNT:[NSNumber numberWithInt:returnCount], P_BEGINNO:[NSNumber numberWithInt:beginNo]}];
    NSLog(@"%d",topicId);
    params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_TOPICID:[NSNumber numberWithInt:topicId]}];//编辑请求内容 {"topicId":self.topicId}
    NSLog(@"%@",[NSNumber numberWithInt:topicId]);
    NSString* encryptedParams = [self base64Encrypt:params];//加密请求内容
    NSLog(@"%@",encryptedParams);
    
    NSString* urlPath = [self getRequestUrlPath:V2APITOPSPAECAILDETAIL operation:R_GETTOPICNEWS params:@{P_REQ:encryptedParams}];//编辑完整api地址
    NSLog(@"%@",urlPath);
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}

//全部专题页面 Bable-

- (void)getAllTopSpecailsWithtarget:(id)target selector:(SEL)selector
{
//    NSMutableDictionary* params;
//    params = [NSMutableDictionary dictionaryWithDictionary:@{P_V2_TOPICID:[NSNumber numberWithInt:topicId]}];//编辑请求内容 {"topicId":self.topicId}
//    NSString* encryptedParams = [self base64Encrypt:params];//加密请求内容
//    
    NSString* urlPath = [self getRequestUrlPath:V2APITOPSPAECAILDETAIL operation:R_GETTOPICS params:@{}];//编辑完整api地址
    
    [[Common shareInstance] showLoadingViewWithMessage:nil];
    [[HttpRequestManager getSharedInstance] getHttpInfo:[Common getUrlByString:urlPath] withUserInfo:nil success:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestSuccess:request];
        NSDictionary *dic = [self dictionaryFromRequest:request];
        objc_msgSend(target, selector, dic);
    } failure:^(ASIHTTPRequest* request){
        [[Common shareInstance] stopLoadingView];
        [self didRequestFailure:request];
        objc_msgSend(target, selector, nil);
    }];
}



@end
